// Licensed to the Apache Software Foundation (ASF) under one
// or more contributor license agreements.  See the NOTICE file
// distributed with this work for additional information
// regarding copyright ownership.  The ASF licenses this file
// to you under the Apache License, Version 2.0 (the
// "License"); you may not use this file except in compliance
// with the License.  You may obtain a copy of the License at
//
//   http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing,
// software distributed under the License is distributed on an
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
// KIND, either express or implied.  See the License for the
// specific language governing permissions and limitations
// under the License.


suite("test_cast_to_float_from_datetimev2_1_part4") {

    // This test case is generated from the correspoinding be UT test case,
    // update this case if the correspoinding be UT test case is updated,
    // e.g.: ../run-be-ut.sh --run --filter=FunctionCastToDecimalTest.* --gen_regression_case
    sql "drop table if exists test_cast_to_float_from_datetimev2_1_part4_4_nullable;"
    sql "create table test_cast_to_float_from_datetimev2_1_part4_4_nullable(f1 int, f2 datetimev2(1)) properties('replication_num'='1');"
    sql """insert into test_cast_to_float_from_datetimev2_1_part4_4_nullable values (0, "0010-01-28 01:59:59.0"),(1, "0010-01-28 01:59:59.0"),(2, "0010-01-28 01:59:59.9"),(3, "0010-01-28 23:00:00.0"),(4, "0010-01-28 23:00:00.0"),(5, "0010-01-28 23:00:00.9"),(6, "0010-01-28 23:00:01.0"),(7, "0010-01-28 23:00:01.0"),(8, "0010-01-28 23:00:01.9"),(9, "0010-01-28 23:00:59.0"),(10, "0010-01-28 23:00:59.0"),(11, "0010-01-28 23:00:59.9"),(12, "0010-01-28 23:01:00.0"),(13, "0010-01-28 23:01:00.0"),(14, "0010-01-28 23:01:00.9"),(15, "0010-01-28 23:01:01.0"),(16, "0010-01-28 23:01:01.0"),(17, "0010-01-28 23:01:01.9"),(18, "0010-01-28 23:01:59.0"),(19, "0010-01-28 23:01:59.0"),
      (20, "0010-01-28 23:01:59.9"),(21, "0010-01-28 23:59:00.0"),(22, "0010-01-28 23:59:00.0"),(23, "0010-01-28 23:59:00.9"),(24, "0010-01-28 23:59:01.0"),(25, "0010-01-28 23:59:01.0"),(26, "0010-01-28 23:59:01.9"),(27, "0010-01-28 23:59:59.0"),(28, "0010-01-28 23:59:59.0"),(29, "0010-01-28 23:59:59.9"),(30, "0010-12-01 00:00:00.0"),(31, "0010-12-01 00:00:00.0"),(32, "0010-12-01 00:00:00.9"),(33, "0010-12-01 00:00:01.0"),(34, "0010-12-01 00:00:01.0"),(35, "0010-12-01 00:00:01.9"),(36, "0010-12-01 00:00:59.0"),(37, "0010-12-01 00:00:59.0"),(38, "0010-12-01 00:00:59.9"),(39, "0010-12-01 00:01:00.0"),
      (40, "0010-12-01 00:01:00.0"),(41, "0010-12-01 00:01:00.9"),(42, "0010-12-01 00:01:01.0"),(43, "0010-12-01 00:01:01.0"),(44, "0010-12-01 00:01:01.9"),(45, "0010-12-01 00:01:59.0"),(46, "0010-12-01 00:01:59.0"),(47, "0010-12-01 00:01:59.9"),(48, "0010-12-01 00:59:00.0"),(49, "0010-12-01 00:59:00.0"),(50, "0010-12-01 00:59:00.9"),(51, "0010-12-01 00:59:01.0"),(52, "0010-12-01 00:59:01.0"),(53, "0010-12-01 00:59:01.9"),(54, "0010-12-01 00:59:59.0"),(55, "0010-12-01 00:59:59.0"),(56, "0010-12-01 00:59:59.9"),(57, "0010-12-01 01:00:00.0"),(58, "0010-12-01 01:00:00.0"),(59, "0010-12-01 01:00:00.9"),
      (60, "0010-12-01 01:00:01.0"),(61, "0010-12-01 01:00:01.0"),(62, "0010-12-01 01:00:01.9"),(63, "0010-12-01 01:00:59.0"),(64, "0010-12-01 01:00:59.0"),(65, "0010-12-01 01:00:59.9"),(66, "0010-12-01 01:01:00.0"),(67, "0010-12-01 01:01:00.0"),(68, "0010-12-01 01:01:00.9"),(69, "0010-12-01 01:01:01.0"),(70, "0010-12-01 01:01:01.0"),(71, "0010-12-01 01:01:01.9"),(72, "0010-12-01 01:01:59.0"),(73, "0010-12-01 01:01:59.0"),(74, "0010-12-01 01:01:59.9"),(75, "0010-12-01 01:59:00.0"),(76, "0010-12-01 01:59:00.0"),(77, "0010-12-01 01:59:00.9"),(78, "0010-12-01 01:59:01.0"),(79, "0010-12-01 01:59:01.0"),
      (80, "0010-12-01 01:59:01.9"),(81, "0010-12-01 01:59:59.0"),(82, "0010-12-01 01:59:59.0"),(83, "0010-12-01 01:59:59.9"),(84, "0010-12-01 23:00:00.0"),(85, "0010-12-01 23:00:00.0"),(86, "0010-12-01 23:00:00.9"),(87, "0010-12-01 23:00:01.0"),(88, "0010-12-01 23:00:01.0"),(89, "0010-12-01 23:00:01.9"),(90, "0010-12-01 23:00:59.0"),(91, "0010-12-01 23:00:59.0"),(92, "0010-12-01 23:00:59.9"),(93, "0010-12-01 23:01:00.0"),(94, "0010-12-01 23:01:00.0"),(95, "0010-12-01 23:01:00.9"),(96, "0010-12-01 23:01:01.0"),(97, "0010-12-01 23:01:01.0"),(98, "0010-12-01 23:01:01.9"),(99, "0010-12-01 23:01:59.0"),
      (100, "0010-12-01 23:01:59.0"),(101, "0010-12-01 23:01:59.9"),(102, "0010-12-01 23:59:00.0"),(103, "0010-12-01 23:59:00.0"),(104, "0010-12-01 23:59:00.9"),(105, "0010-12-01 23:59:01.0"),(106, "0010-12-01 23:59:01.0"),(107, "0010-12-01 23:59:01.9"),(108, "0010-12-01 23:59:59.0"),(109, "0010-12-01 23:59:59.0"),(110, "0010-12-01 23:59:59.9"),(111, "0010-12-28 00:00:00.0"),(112, "0010-12-28 00:00:00.0"),(113, "0010-12-28 00:00:00.9"),(114, "0010-12-28 00:00:01.0"),(115, "0010-12-28 00:00:01.0"),(116, "0010-12-28 00:00:01.9"),(117, "0010-12-28 00:00:59.0"),(118, "0010-12-28 00:00:59.0"),(119, "0010-12-28 00:00:59.9"),
      (120, "0010-12-28 00:01:00.0"),(121, "0010-12-28 00:01:00.0"),(122, "0010-12-28 00:01:00.9"),(123, "0010-12-28 00:01:01.0"),(124, "0010-12-28 00:01:01.0"),(125, "0010-12-28 00:01:01.9"),(126, "0010-12-28 00:01:59.0"),(127, "0010-12-28 00:01:59.0"),(128, "0010-12-28 00:01:59.9"),(129, "0010-12-28 00:59:00.0"),(130, "0010-12-28 00:59:00.0"),(131, "0010-12-28 00:59:00.9"),(132, "0010-12-28 00:59:01.0"),(133, "0010-12-28 00:59:01.0"),(134, "0010-12-28 00:59:01.9"),(135, "0010-12-28 00:59:59.0"),(136, "0010-12-28 00:59:59.0"),(137, "0010-12-28 00:59:59.9"),(138, "0010-12-28 01:00:00.0"),(139, "0010-12-28 01:00:00.0"),
      (140, "0010-12-28 01:00:00.9"),(141, "0010-12-28 01:00:01.0"),(142, "0010-12-28 01:00:01.0"),(143, "0010-12-28 01:00:01.9"),(144, "0010-12-28 01:00:59.0"),(145, "0010-12-28 01:00:59.0"),(146, "0010-12-28 01:00:59.9"),(147, "0010-12-28 01:01:00.0"),(148, "0010-12-28 01:01:00.0"),(149, "0010-12-28 01:01:00.9"),(150, "0010-12-28 01:01:01.0"),(151, "0010-12-28 01:01:01.0"),(152, "0010-12-28 01:01:01.9"),(153, "0010-12-28 01:01:59.0"),(154, "0010-12-28 01:01:59.0"),(155, "0010-12-28 01:01:59.9"),(156, "0010-12-28 01:59:00.0"),(157, "0010-12-28 01:59:00.0"),(158, "0010-12-28 01:59:00.9"),(159, "0010-12-28 01:59:01.0"),
      (160, "0010-12-28 01:59:01.0"),(161, "0010-12-28 01:59:01.9"),(162, "0010-12-28 01:59:59.0"),(163, "0010-12-28 01:59:59.0"),(164, "0010-12-28 01:59:59.9"),(165, "0010-12-28 23:00:00.0"),(166, "0010-12-28 23:00:00.0"),(167, "0010-12-28 23:00:00.9"),(168, "0010-12-28 23:00:01.0"),(169, "0010-12-28 23:00:01.0"),(170, "0010-12-28 23:00:01.9"),(171, "0010-12-28 23:00:59.0"),(172, "0010-12-28 23:00:59.0"),(173, "0010-12-28 23:00:59.9"),(174, "0010-12-28 23:01:00.0"),(175, "0010-12-28 23:01:00.0"),(176, "0010-12-28 23:01:00.9"),(177, "0010-12-28 23:01:01.0"),(178, "0010-12-28 23:01:01.0"),(179, "0010-12-28 23:01:01.9"),
      (180, "0010-12-28 23:01:59.0"),(181, "0010-12-28 23:01:59.0"),(182, "0010-12-28 23:01:59.9"),(183, "0010-12-28 23:59:00.0"),(184, "0010-12-28 23:59:00.0"),(185, "0010-12-28 23:59:00.9"),(186, "0010-12-28 23:59:01.0"),(187, "0010-12-28 23:59:01.0"),(188, "0010-12-28 23:59:01.9"),(189, "0010-12-28 23:59:59.0"),(190, "0010-12-28 23:59:59.0"),(191, "0010-12-28 23:59:59.9"),(192, "0100-01-01 00:00:00.0"),(193, "0100-01-01 00:00:00.0"),(194, "0100-01-01 00:00:00.9")
      ,(195, null);
    """

    sql "set enable_strict_cast=true;"

    test {
        sql """select f1, cast(f2 as float) from test_cast_to_float_from_datetimev2_1_part4_4_nullable order by 1;"""
        exception ""
    }
    sql "set enable_strict_cast=false;"
    qt_sql_4_non_strict 'select f1, cast(f2 as float) from test_cast_to_float_from_datetimev2_1_part4_4_nullable order by 1;'

    sql "drop table if exists test_cast_to_float_from_datetimev2_1_part4_4_not_nullable;"
    sql "create table test_cast_to_float_from_datetimev2_1_part4_4_not_nullable(f1 int, f2 datetimev2(1)) properties('replication_num'='1');"
    sql """insert into test_cast_to_float_from_datetimev2_1_part4_4_not_nullable values (0, "0010-01-28 01:59:59.0"),(1, "0010-01-28 01:59:59.0"),(2, "0010-01-28 01:59:59.9"),(3, "0010-01-28 23:00:00.0"),(4, "0010-01-28 23:00:00.0"),(5, "0010-01-28 23:00:00.9"),(6, "0010-01-28 23:00:01.0"),(7, "0010-01-28 23:00:01.0"),(8, "0010-01-28 23:00:01.9"),(9, "0010-01-28 23:00:59.0"),(10, "0010-01-28 23:00:59.0"),(11, "0010-01-28 23:00:59.9"),(12, "0010-01-28 23:01:00.0"),(13, "0010-01-28 23:01:00.0"),(14, "0010-01-28 23:01:00.9"),(15, "0010-01-28 23:01:01.0"),(16, "0010-01-28 23:01:01.0"),(17, "0010-01-28 23:01:01.9"),(18, "0010-01-28 23:01:59.0"),(19, "0010-01-28 23:01:59.0"),
      (20, "0010-01-28 23:01:59.9"),(21, "0010-01-28 23:59:00.0"),(22, "0010-01-28 23:59:00.0"),(23, "0010-01-28 23:59:00.9"),(24, "0010-01-28 23:59:01.0"),(25, "0010-01-28 23:59:01.0"),(26, "0010-01-28 23:59:01.9"),(27, "0010-01-28 23:59:59.0"),(28, "0010-01-28 23:59:59.0"),(29, "0010-01-28 23:59:59.9"),(30, "0010-12-01 00:00:00.0"),(31, "0010-12-01 00:00:00.0"),(32, "0010-12-01 00:00:00.9"),(33, "0010-12-01 00:00:01.0"),(34, "0010-12-01 00:00:01.0"),(35, "0010-12-01 00:00:01.9"),(36, "0010-12-01 00:00:59.0"),(37, "0010-12-01 00:00:59.0"),(38, "0010-12-01 00:00:59.9"),(39, "0010-12-01 00:01:00.0"),
      (40, "0010-12-01 00:01:00.0"),(41, "0010-12-01 00:01:00.9"),(42, "0010-12-01 00:01:01.0"),(43, "0010-12-01 00:01:01.0"),(44, "0010-12-01 00:01:01.9"),(45, "0010-12-01 00:01:59.0"),(46, "0010-12-01 00:01:59.0"),(47, "0010-12-01 00:01:59.9"),(48, "0010-12-01 00:59:00.0"),(49, "0010-12-01 00:59:00.0"),(50, "0010-12-01 00:59:00.9"),(51, "0010-12-01 00:59:01.0"),(52, "0010-12-01 00:59:01.0"),(53, "0010-12-01 00:59:01.9"),(54, "0010-12-01 00:59:59.0"),(55, "0010-12-01 00:59:59.0"),(56, "0010-12-01 00:59:59.9"),(57, "0010-12-01 01:00:00.0"),(58, "0010-12-01 01:00:00.0"),(59, "0010-12-01 01:00:00.9"),
      (60, "0010-12-01 01:00:01.0"),(61, "0010-12-01 01:00:01.0"),(62, "0010-12-01 01:00:01.9"),(63, "0010-12-01 01:00:59.0"),(64, "0010-12-01 01:00:59.0"),(65, "0010-12-01 01:00:59.9"),(66, "0010-12-01 01:01:00.0"),(67, "0010-12-01 01:01:00.0"),(68, "0010-12-01 01:01:00.9"),(69, "0010-12-01 01:01:01.0"),(70, "0010-12-01 01:01:01.0"),(71, "0010-12-01 01:01:01.9"),(72, "0010-12-01 01:01:59.0"),(73, "0010-12-01 01:01:59.0"),(74, "0010-12-01 01:01:59.9"),(75, "0010-12-01 01:59:00.0"),(76, "0010-12-01 01:59:00.0"),(77, "0010-12-01 01:59:00.9"),(78, "0010-12-01 01:59:01.0"),(79, "0010-12-01 01:59:01.0"),
      (80, "0010-12-01 01:59:01.9"),(81, "0010-12-01 01:59:59.0"),(82, "0010-12-01 01:59:59.0"),(83, "0010-12-01 01:59:59.9"),(84, "0010-12-01 23:00:00.0"),(85, "0010-12-01 23:00:00.0"),(86, "0010-12-01 23:00:00.9"),(87, "0010-12-01 23:00:01.0"),(88, "0010-12-01 23:00:01.0"),(89, "0010-12-01 23:00:01.9"),(90, "0010-12-01 23:00:59.0"),(91, "0010-12-01 23:00:59.0"),(92, "0010-12-01 23:00:59.9"),(93, "0010-12-01 23:01:00.0"),(94, "0010-12-01 23:01:00.0"),(95, "0010-12-01 23:01:00.9"),(96, "0010-12-01 23:01:01.0"),(97, "0010-12-01 23:01:01.0"),(98, "0010-12-01 23:01:01.9"),(99, "0010-12-01 23:01:59.0"),
      (100, "0010-12-01 23:01:59.0"),(101, "0010-12-01 23:01:59.9"),(102, "0010-12-01 23:59:00.0"),(103, "0010-12-01 23:59:00.0"),(104, "0010-12-01 23:59:00.9"),(105, "0010-12-01 23:59:01.0"),(106, "0010-12-01 23:59:01.0"),(107, "0010-12-01 23:59:01.9"),(108, "0010-12-01 23:59:59.0"),(109, "0010-12-01 23:59:59.0"),(110, "0010-12-01 23:59:59.9"),(111, "0010-12-28 00:00:00.0"),(112, "0010-12-28 00:00:00.0"),(113, "0010-12-28 00:00:00.9"),(114, "0010-12-28 00:00:01.0"),(115, "0010-12-28 00:00:01.0"),(116, "0010-12-28 00:00:01.9"),(117, "0010-12-28 00:00:59.0"),(118, "0010-12-28 00:00:59.0"),(119, "0010-12-28 00:00:59.9"),
      (120, "0010-12-28 00:01:00.0"),(121, "0010-12-28 00:01:00.0"),(122, "0010-12-28 00:01:00.9"),(123, "0010-12-28 00:01:01.0"),(124, "0010-12-28 00:01:01.0"),(125, "0010-12-28 00:01:01.9"),(126, "0010-12-28 00:01:59.0"),(127, "0010-12-28 00:01:59.0"),(128, "0010-12-28 00:01:59.9"),(129, "0010-12-28 00:59:00.0"),(130, "0010-12-28 00:59:00.0"),(131, "0010-12-28 00:59:00.9"),(132, "0010-12-28 00:59:01.0"),(133, "0010-12-28 00:59:01.0"),(134, "0010-12-28 00:59:01.9"),(135, "0010-12-28 00:59:59.0"),(136, "0010-12-28 00:59:59.0"),(137, "0010-12-28 00:59:59.9"),(138, "0010-12-28 01:00:00.0"),(139, "0010-12-28 01:00:00.0"),
      (140, "0010-12-28 01:00:00.9"),(141, "0010-12-28 01:00:01.0"),(142, "0010-12-28 01:00:01.0"),(143, "0010-12-28 01:00:01.9"),(144, "0010-12-28 01:00:59.0"),(145, "0010-12-28 01:00:59.0"),(146, "0010-12-28 01:00:59.9"),(147, "0010-12-28 01:01:00.0"),(148, "0010-12-28 01:01:00.0"),(149, "0010-12-28 01:01:00.9"),(150, "0010-12-28 01:01:01.0"),(151, "0010-12-28 01:01:01.0"),(152, "0010-12-28 01:01:01.9"),(153, "0010-12-28 01:01:59.0"),(154, "0010-12-28 01:01:59.0"),(155, "0010-12-28 01:01:59.9"),(156, "0010-12-28 01:59:00.0"),(157, "0010-12-28 01:59:00.0"),(158, "0010-12-28 01:59:00.9"),(159, "0010-12-28 01:59:01.0"),
      (160, "0010-12-28 01:59:01.0"),(161, "0010-12-28 01:59:01.9"),(162, "0010-12-28 01:59:59.0"),(163, "0010-12-28 01:59:59.0"),(164, "0010-12-28 01:59:59.9"),(165, "0010-12-28 23:00:00.0"),(166, "0010-12-28 23:00:00.0"),(167, "0010-12-28 23:00:00.9"),(168, "0010-12-28 23:00:01.0"),(169, "0010-12-28 23:00:01.0"),(170, "0010-12-28 23:00:01.9"),(171, "0010-12-28 23:00:59.0"),(172, "0010-12-28 23:00:59.0"),(173, "0010-12-28 23:00:59.9"),(174, "0010-12-28 23:01:00.0"),(175, "0010-12-28 23:01:00.0"),(176, "0010-12-28 23:01:00.9"),(177, "0010-12-28 23:01:01.0"),(178, "0010-12-28 23:01:01.0"),(179, "0010-12-28 23:01:01.9"),
      (180, "0010-12-28 23:01:59.0"),(181, "0010-12-28 23:01:59.0"),(182, "0010-12-28 23:01:59.9"),(183, "0010-12-28 23:59:00.0"),(184, "0010-12-28 23:59:00.0"),(185, "0010-12-28 23:59:00.9"),(186, "0010-12-28 23:59:01.0"),(187, "0010-12-28 23:59:01.0"),(188, "0010-12-28 23:59:01.9"),(189, "0010-12-28 23:59:59.0"),(190, "0010-12-28 23:59:59.0"),(191, "0010-12-28 23:59:59.9"),(192, "0100-01-01 00:00:00.0"),(193, "0100-01-01 00:00:00.0"),(194, "0100-01-01 00:00:00.9");
    """

    sql "set enable_strict_cast=true;"

    test {
        sql """select f1, cast(f2 as float) from test_cast_to_float_from_datetimev2_1_part4_4_not_nullable order by 1;"""
        exception ""
    }
    sql "set enable_strict_cast=false;"
    qt_sql_4_non_strict 'select f1, cast(f2 as float) from test_cast_to_float_from_datetimev2_1_part4_4_not_nullable order by 1;'

}